package com.wz.project.outTray.outTray.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.outTray.outTray.domain.OutTrayMsg;
import com.wz.project.outTray.outTray.service.IOutTrayMsgService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 出库条码Controller
 * 
 * @author wld
 * @date 2023-10-19
 */
@Controller
@RequestMapping("/outTray/outTray")
public class OutTrayMsgController extends BaseController
{
    private String prefix = "rf";

    @Autowired
    private IOutTrayMsgService outTrayMsgService;

    @RequiresPermissions("outTray:outTray:view")
    @GetMapping()
    public String outTray()
    {
        return prefix + "/outTray";
    }

    /**
     * 查询出库条码列表
     */
//    @RequiresPermissions("outTray:outTray:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OutTrayMsg outTrayMsg)
    {
        if (outTrayMsg.getStockoutGuid() != null && !"".equals(outTrayMsg.getStockoutGuid())) {
            outTrayMsg.setStockoutGuid(String.format("%010d", Long.parseLong(outTrayMsg.getStockoutGuid())));
        } else {
            outTrayMsg.setStockoutGuid(String.format("%010d", 0));
        }
        startPage();
        List<OutTrayMsg> list = outTrayMsgService.selectOutTrayMsgList(outTrayMsg);
        return getDataTable(list);
    }

    /**
     * 导出出库条码列表
     */
    @RequiresPermissions("outTray:outTray:export")
    @Log(title = "出库条码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OutTrayMsg outTrayMsg)
    {
        List<OutTrayMsg> list = outTrayMsgService.selectOutTrayMsgList(outTrayMsg);
        ExcelUtil<OutTrayMsg> util = new ExcelUtil<OutTrayMsg>(OutTrayMsg.class);
        return util.exportExcel(list, "outTray");
    }

    /**
     * 新增出库条码
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库条码
     */
    @RequiresPermissions("outTray:outTray:add")
    @Log(title = "出库条码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OutTrayMsg outTrayMsg)
    {
        return toAjax(outTrayMsgService.insertOutTrayMsg(outTrayMsg));
    }

    /**
     * 修改出库条码
     */
    @GetMapping("/edit/{stockoutGuid}")
    public String edit(@PathVariable("stockoutGuid") String stockoutGuid, ModelMap mmap)
    {
        OutTrayMsg outTrayMsg = outTrayMsgService.selectOutTrayMsgById(stockoutGuid);
        mmap.put("outTrayMsg", outTrayMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库条码
     */
    @RequiresPermissions("outTray:outTray:edit")
    @Log(title = "出库条码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OutTrayMsg outTrayMsg)
    {
        return toAjax(outTrayMsgService.updateOutTrayMsg(outTrayMsg));
    }

    /**
     * 删除出库条码
     */
    @RequiresPermissions("outTray:outTray:remove")
    @Log(title = "出库条码", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(outTrayMsgService.deleteOutTrayMsgByIds(ids));
    }
}
